/**
 * Title: SharedPreferencesUtil.java
 * Description:
 * author: kotomifi
 * date: Jul 19, 2014
 * ©2014 apping 社区
 */
package com.apping.demo.bbs.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * 操作SharedPreferences对象
 * 提供读写接口
 */
public class SharedPreferencesUtil {

	SharedPreferences preferences;
	SharedPreferences.Editor editor;
	Context mContext;
	
	public SharedPreferencesUtil(Context context) {
		mContext = context;
	}
	
	public void writeString(String fileName, String key, String data) {
		preferences = mContext.getSharedPreferences(fileName, Context.MODE_WORLD_READABLE);
		editor = preferences.edit();
		editor.putString(key, data);
		editor.commit();
	}
	
	public void writeInt(String fileName, String key, int data) {
		preferences = mContext.getSharedPreferences(fileName, Context.MODE_WORLD_READABLE);
		editor = preferences.edit();
		editor.putInt(key, data);
		editor.commit();
	}
	
	public void writeLong(String fileName, String key, long data) {
		preferences = mContext.getSharedPreferences(fileName, Context.MODE_WORLD_READABLE);
		editor = preferences.edit();
		editor.putLong(key, data);
		editor.commit();
	}
	
	public String readString(String fileName, String key) {
		preferences = mContext.getSharedPreferences(fileName, Context.MODE_WORLD_READABLE);
		return preferences.getString(key, null);
	}
	
	public int readInt(String fileName, String key) {
		preferences = mContext.getSharedPreferences(fileName, Context.MODE_WORLD_READABLE);
		return preferences.getInt(key, 0);
	}
	
	public long readLong(String fileName, String key) {
		preferences = mContext.getSharedPreferences(fileName, Context.MODE_WORLD_READABLE);
		return preferences.getLong(key, 0);
	}
}
